<% content_for :css do %>
  <%= stylesheet_link_tag 'infos_index' %>
<% end %>  
<%= render :file => 'infos/_nav_bar.html' %>
<script type="text/javascript" charset="utf-8">
  function hide_all_spreaded() {
    $$('div.spreaded').each(function(info) {
      info.hide();
    });
    $('hide_all_spreaded_link').hide();
    $('show_all_spreaded_link').show();
  }
  
  function show_all_spreaded() {
    $$('div.spreaded').each(function(info) {
      info.show();
    });
    $('hide_all_spreaded_link').show();
    $('show_all_spreaded_link').hide();
  }
</script>
<div id="types" class='corner'>
  <div class='type <%= params[:info_type_id] == '%' ? 'h' : '' %>'>
    <%= link_to '全部', infos_url(:info_type_id => '%') %>
  </div>
  <% InfoType.all.each do |type| %>
  <div class='type <%= params[:info_type_id].to_i == type.id ? 'h' : '' %>'>
    <%= link_to type.name, infos_url(:info_type_id => type.id), :title => type.name %>
  </div>
  <% end %>
</div>
<div id='info_admin'>
  <div class='head'>
    <div class='title'>  
      <h1>资讯管理</h1>
    </div>
    <div class='tools'>
      <%= link_to '发布新资讯',new_info_url %>
      <%= link_to_function '隐藏已推广','hide_all_spreaded()', :id => 'hide_all_spreaded_link' %>
      <%= link_to_function '显示已推广','show_all_spreaded()', :id => 'show_all_spreaded_link', :style => 'display:none' %>
    </div>
  </div>
  <div class='infos'>
    <div class='tip'>
      共<b><%= @infos.total_entries %></b>条,头<b><%= @infos.size %></b>条,其中<b><%= @spreadeds_count %></b>条已经推广
    </div>
    <% @infos.each do |info| %>
    <div id='info_<%= info.id %>' class='info <%= info.spreaded? ? 'spreaded' : '' %>'>
      <div class='<%= info.money_purpose.gift? ? 'title money' : 'title' %>'>
        <%= info.info_type.name %>-<%= link_to info.title, info_url(info), :target => :_blank, :title => info.title %><span>创建于<%=  time_ago_in_words info.created_at, false %>前</span>
      </div>
      <div class='stat'>
        <div class='emails'>
          <%= supports_email %><small><%= info.emails_count %></small>
        </div>
        <div class='sms'>
          <%= supports_sms %><small><%= info.sms_count %></small>
        </div>
        <% if info.money_purpose.gift? %>
        <div class='money'>
          <%= image_tag 'base/money.jpg', :size => '14x14' %>+ <%= info.money %>
        </div>
        <% end %>
      </div>
      <div class='tools'>
        <div id="spread_tools_<%= info.id %>" class='spread'>
          <%= render :partial => 'spread_tools.html', :locals => {:info => info} %>
        </div>
        <div class='edit'>
          <%= link_to "编辑", edit_info_url(info) %>
        </div>
        <div class='destroy'>
          <%= link_to_remote "删除", 
                :confirm =>'删除该资讯，确认码？',
                :url => info_url(info),
                :method => :delete,
                :loading => "Effect.Fade('info_#{info.id}')"
            %>
        </div>
      </div>
    </div>  
    <% end %>  
    <div class='tip bottom'>
      共<b><%= @infos.total_entries %></b>条,头<b><%= @infos.size %></b>条,其中<b><%= @spreadeds_count %></b>条已经推广
    </div>
  </div>
</div>